package cloud.seri.iot.manager.service.mapper

import cloud.seri.iot.manager.domain.Product
import cloud.seri.iot.manager.service.dto.ProductDTO
import cloud.seri.iot.manager.service.example.ProductExample
import com.aliyuncs.iot.model.v20180120.CreateProductResponse

import org.mapstruct.Mapper
import org.mapstruct.Mapping
import org.mapstruct.Mappings

/**
 * Mapper for the entity [Product] and its DTO [ProductDTO].
 */
@Mapper(componentModel = "spring", uses = [])
interface ProductMapper : EntityMapper<ProductDTO, Product>
{
    @Mappings(
        Mapping(target = "devices", ignore = true)
    )
    override fun toEntity(dto: ProductDTO): Product

    @Mappings(
        Mapping(target = "deviceType", source = "nodeType")
    )
    fun createProductEntity(data: CreateProductResponse.Data): Product

    fun productExampleToEntity(example: ProductExample?): Product?

    fun fromId(productKey: String?): Product?
}
